Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: use unified API spec, and go generator #39

Merged
merged 6 commits into from
Aug 30, 2024
Merged

Conversation

szuperaz
Copy link
Collaborator

@szuperaz szuperaz commented May 24, 2024

Go generator: https://github.com/GetStream/chat/pull/6536

Breaking changes

All products

  • Dates: instead of ISO date strings, the SDK will use Date objects both for requests (except for filter_conditions) and responses
const call = client.video.call('default', '123');
// New format - Date object instead of ISO date string
call.getOrCreate({data: {starts_at: new Date()}})

// For filter_conditions - no change
client.video.queryCalls({
  filter_conditions: {
    starts_at: { $gt: inNext30mins.toISOString() },
  },
});
  • All enums, except for OwnCabaility are replaced with string union types, so if you had something like this before: CreateDeviceRequestPushProviderEnum.FIREBASE you need to change this to 'firebase'
  • Some models were renamed/deleted, if you're using JS these changes won't affect you, if you're using TS, you can rely on you IDE to help to make the necessary changes

Common (StreamClient class)

  • This version of the SDK now uses the new, moderation v2 endpoints (ban/unban, mute/unmute and flag methods), to enable access to these APIs, please contact support
// banUser is now ban
// Method moved to StreamModerationClient
// user_id renamed to banned_by_id
client.moderation.ban({
  target_user_id: '<bad user id>',
  banned_by_id: '<moderator id>',
  reason: '<reason>',
});

// unbanUser is now unban
// Method moved to StreamModerationClient
// targetUserId renamed to target_user_id
// id renamed to created_by
client.moderation.unban({
    target_user_id: '<bad user id>',
    created_by: '<moderator id>',
 });

// muteUser is now mute
// Method moved to StreamModerationClient
client.moderation.mute({
      target_ids: ['user to mute id'],
      user_id: 'user id',
})

// unmuteUser is now unmute
// Method moved to StreamModerationClient
client.moderation.unmute({
      target_ids: ['user to unmute id'],
      user_id: 'user id',
})

// flagMessage is removed, instead you can usethe following method:
client.moderation.flag({
      entity_type: 'stream:chat:v1:message',
      entity_id: messageId,
      user_id: 'user-id',
      // You can choose from a list of predefined reasons
      reason: 'hate',
});
  • Upserting users has a simplified syntax:
// New, simplified syntax
await client.upsertUsers([
  { name: 'John', id: 'john' },
  { name: 'Jack', id: 'jack' },
  { name: 'Jane', id: 'jane' },
  { name: 'Sara', id: 'sara' },
]);
  • Some methods were renamed, and/or their parameters were slightly changed:
// user_id instead of userId
client.deleteDevice({ id: device.id, user_id: user.id })

// user_id instead of userId
client.listDevices({ user_id: user.id })

// wrap the request with push_provider
client.upsertPushProvider({ push_provider: pushProvider })

// banUser renamed
client.ban({ target_user_id: 'jack', user_id: 'sara' })

// unbanUser renamed to unban, request parameters have snake_case, instead of camelCase
client.unban({ target_user_id: 'john', created_by: 'jack', channel_cid: 'cats' })

// user_id instead of userId
client.exportUser({user_id: 'tom'})

// wrap the request with payload
client.queryBannedUsers({ payload: { filter_conditions: {} } }

// wrap the request with payload
client.queryUsers({ payload: { filter_conditions: { name: { $autocomplete: 'tom' } } } })

// sendCustomEventToUser renamed and signature is changed
client.chat.sendUserCustomEvent({ user_id: 'sophie', event: { type: 'my-custom-event' } })

// getAppSettings renamed
client.getApp()

// updateAppSettings renamed
client.updateApp( /* ... */ )

// getTaskStatus renamed
client.getTask({ id: 'task-id' })

// user_id instead of userId
client.getBlockedUsers({ user_id: user.id })

Video (StreamVideoClient and StreamCall classes)

  • All video models used to have a Video prefix, which is now gone, so for example: VideoDeleteCallResponse is changed to DeleteCallResponse
  • Some methods were renamed, and/or their parameters were slightly changed:

StreamVideoClient class

// queryCallStatistics renamed
client.video.queryCallStats( /* ... */ )

// updateCallType - call type name is part of the request object now
client.video.updateCallType({ name: callTypeName, grants: { user: userGrants, call_member: callMemberGrants } })

// listExternalStorages moved to StreamClient
client.listExternalStorage()

// createExternalStorage moved to StreamClient
client.createExternalStorage({ name: 'my-storage', bucket: 'my-bucket', storage_type: 's3' })

// deleteExternalStorage moved to StreamClient
client.deleteExternalStorage({ name: 'my-storage' })

// updateExternalStorage moved to StreamClient - storage name is part of the request object now
client.updateExternalStorage({ name: 'my-storage',  bucket: 'new-bucket', storage_type: 's3' })

// checkExternalStorage moved to StreamClient
client.checkExternalStorage({ name: 'my-storage' })

StreamCall class

// endCall renamed
call.end()

// members_limit instead of membersLimit
call.get({ members_limit: 20 })

// getSessionStatistics renamed
call.getCallStats({ session: '<session id>' })

// getCallStats moved to StreamVideoClient
client.video.queryCallStats({ filter_conditions: { call_cid: call.cid } })

// sendCustomEvent renamed
call.sendCallEvent({ custom: { 'render-animation': 'balloons' })

// pinVideo renamed
call.videoPin( /* ... */ )

// unpinVideo renamed
call.videoUnpin( /* ... */ )

Chat (StreamChatClient and StreamChannel classes)

  • name and image of a Channel need to be provided as custom data:
// Old format
const response = await channel.getOrCreate({
  data: { created_by_id: user.id, name: 'Cats' },
});

// New format
const response = await channel.getOrCreate({
  data: { created_by_id: user.id, custom: { name: 'Cats' } },
});
  • Some methods were renamed, and/or their parameters were slightly changed:

StreamChatClient class

// createBlockList moved to StreamClient
client.createBlockList({ name: 'fruits', words: ['apple', 'banana'] })

// listBlockLists moved to StreamClient
client.listBlockLists()

// getBlockList moved to StreamClient
client.getBlockList({ name: 'fruits' })

// updateBlockList moved to StreamClient, request object now contains block list name as well
client.updateBlockList({ name: 'fruits', words: ['apple', 'avocado', 'banana'] })

// deleteBlockList moved to StreamClient
client.deleteBlockList({ name: 'fruits' })

// updateChannelType - request object now contains the channel type name as well 
client.chat.updateChannelType({ name: channelType, automod: 'simple', automod_behavior: 'block', max_message_length: 20000 })

// searchMessages renamed, request object should be wrapped with payload
client.chat.search({ payload: { 
  filter_conditions: { members: { $in: ['user if'] } },
  message_filter_conditions: { text: { $autocomplete: 'check' } },
  }
});

// getExportStatus renamed
client.chat.getExportChannelsStatus({ id: 'task-id' })

// updateCommand - request object now contains the command name as well
client.chat.updateCommand({ name: commandName, description: 'Updated descrpition' })

StreamChannel class

// hardDelete renamed to hard_delete
channel.delete({ hard_delete: true })

// updatePartia renamed
channel.updateChannelPartial({ set: { cooldown: 100 }, unset: [] })

// queryMembers - request object should be wrapped with payload
channel.queryMembers({ payload: { filter_conditions: { name: { $autocomplete: '2' } } } })

// mute was moved to StreamChatClient
client.chat.muteChannel({ user_id: 'user-id', channel_cids: [channel.cid] })

// unmute was moved to StreamChatClient
client.chat.unmuteChannel({ user_id: 'user-id', channel_cids: [channel.cid] })

// deleteMesage moved to StreamChatClient, deleted_by instead of deletedBy
client.chat.deleteMessage({ id: messageId, deleted_by: 'user-id' })

// updateMessage moved to StreamChatClient - the request object now contains the message id as well
client.chat.updateMessage({id: messageId, message: { text: 'Hi 👋' }})

// updateMessagePartial moved to StreamChatClient - the request object now contains the message id as well
client.chat.updateMessagePartial({id: messageId, set: { text: 'check this out: https://getstream.io/' } })

// getMessage moved to StreamChatClient, show_deleted_message instead of showDeletedMessage
client.chat.getMessage({ id: messageId, show_deleted_message: true })

// translateMessage moved to StreamChatClient, message id is now part of the request object
client.chat.translateMessage({ id: messageId, language: 'hu' })

// getMessagesAround renamed and moved to StreamChatClient, request object now uses snake_case instead of camelCase
client.chat.getReplies({ id_around: messageId })

// getOpenGraphData renamed and moved to StreamChatClient
client.getOG({ url: 'https://getstream.io/' })

// sendMessageReaction renamed and moved to StreamChatClient, request object now also includes message id
client.chat.sendReaction({ id: messageId, reaction: { type: 'like', user_id: user.id } })

// deleteMessageReaction renamed and moved to StreamChatClient, request object now also includes message id, request now uses snake case
client.chat.deleteReaction({ id: messageId, type: 'like', user_id: user.id })

// getMessageReactions renamed and moved to StreamChatClient, request object now also includes message id 
client.chat.getReactions({ id: messageId })

// sendCustomEvent renamed, signature changed
channel.sendEvent({ event: { type: 'my-event', user_id: user.id } })

@szuperaz szuperaz marked this pull request as ready for review July 24, 2024 14:11
@szuperaz szuperaz marked this pull request as draft July 24, 2024 14:11
@szuperaz szuperaz changed the base branch from unified-api-spec to main July 30, 2024 13:41
@szuperaz szuperaz force-pushed the go-generator branch 9 times, most recently from 1e103b5 to 8d93df4 Compare August 2, 2024 08:17
@szuperaz szuperaz force-pushed the go-generator branch 4 times, most recently from 05245f4 to c148f1d Compare August 6, 2024 13:17
@szuperaz szuperaz changed the title feat: Go openapi generator - in progress feat: Go openapi generator Aug 6, 2024
@szuperaz szuperaz marked this pull request as ready for review August 6, 2024 13:18
@szuperaz szuperaz force-pushed the go-generator branch 5 times, most recently from 852026e to 0f54a24 Compare August 8, 2024 13:01
@szuperaz szuperaz requested a review from oliverlaz August 8, 2024 13:01
@szuperaz szuperaz force-pushed the go-generator branch 2 times, most recently from 7c13772 to f5852ce Compare August 8, 2024 13:10
@szuperaz szuperaz force-pushed the go-generator branch 2 times, most recently from c53e73c to 791bff8 Compare August 29, 2024 08:50
@szuperaz szuperaz changed the title feat: Go openapi generator feat!: use unified API spec, and go generator Aug 30, 2024
@szuperaz szuperaz merged commit 1bba83d into main Aug 30, 2024
7 checks passed
@szuperaz szuperaz deleted the go-generator branch August 30, 2024 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant